package com.baizhi.lfk.controller;


import com.baizhi.lfk.entity.Category;
import com.baizhi.lfk.service.CategoryService;
import com.baizhi.lfk.vo.CategoryVO;
import com.baizhi.lfk.vo.PageVO;
import com.baizhi.lfk.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@CrossOrigin
@ResponseBody
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //查询所有一级类别
    @RequestMapping("/category/queryOnePage")
    public CategoryVO queryOneCategoryPage(@RequestBody PageVO pageVO){
        System.out.println(pageVO.getPage());
        System.out.println(pageVO.getPageSize());
        return categoryService.queryOneCategoryPage(pageVO);
    }
    //添加类别
    @RequestMapping("/category/add")
    public ResultVO registeCategory(@RequestBody Category category){
        return categoryService.registCategory(category);
    }

    //修改的数据回显  根据id查询类别信息
    @RequestMapping("/category/queryById")
    public Category queryById(Integer id){
        return categoryService.queryById(id);
    }

    //修改
    @RequestMapping("/category/update")
    public ResultVO modifyCateGory(@RequestBody Category category){
        return categoryService.modifyCategory(category);
    }

    //删除
    @RequestMapping("/category/delete")
    public ResultVO removeCategory(@RequestBody Category category){
        return categoryService.removeCategory(category);
    }

    //查询一级类别下所有的二级类别
    @RequestMapping("/category/queryTwoPage")
    public CategoryVO queryTwoCategoryPage(@RequestBody PageVO pageVO){
        return categoryService.queryTwoCategoryPage(pageVO);
    }

    //查询所有一级类别
    @RequestMapping("/category/queryByLevelsCategory")
    public List<Category> queryAllCategory(){
        return categoryService.queryAllOneCategory();
    }


}
